/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nus.dataaccess.dao.util;

import java.io.InputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
//import org.hibernate.util.DTDEntityResolver;
import org.xml.sax.InputSource;

/**
 *
 * @author robin.foe
 */
public class ImportFromClassPathEntityResolver  {
    //extends DTDEntityResolver
//
//    private static Log log = LogFactory.getLog(ImportFromClassPathEntityResolver.class);
//    //private static final Log log = LogFactory.getLog(ImportFromClassPathEntityResolver.class);
//    // This is the prefix of SYSTEM entity identifiers which are not URLs
//    private static final String PREFIX = "file://";
//
//    @Override
//    public InputSource resolveEntity(String publicId, String systemId) {
//        log.debug("Trying to resolve system id: " + systemId);
//        if (systemId != null && systemId.startsWith(PREFIX)) {
//            // Remove the initial slash and look it up
//            String resource = systemId.substring(PREFIX.length());
//            log.debug("Looking up entity on classpath: " + resource);
//
//            InputStream stream = getClass().getResourceAsStream(resource);
//            if (stream == null) {
//                stream = getClass().getClassLoader()
//                        .getResourceAsStream(resource);
//            }
//            if (stream == null) {
//                stream = Thread.currentThread().getContextClassLoader()
//                        .getResourceAsStream(resource);
//            }
//            if (stream == null) {
//                log.error("Couldn't find entity in classpath: " + resource);
//            } else {
//                log.debug("Found entity on classpath: " + resource);
//                InputSource source = new InputSource(stream);
//                source.setPublicId(publicId);
//                source.setSystemId(systemId);
//                return source;
//            }
//        }
//        return super.resolveEntity(publicId, systemId);
//    }
}
